package com.neuedu.helloworld.controller;//package com.neuedu.helloworld.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class IndexController {



    @RequestMapping("/")
    public String test(){

        return "欢迎访问";

    }


    @RequestMapping("/cal")
    public String cal(int numa, int numb){

        return String.valueOf( numa / numb);

    }


    /**
     * 在某一个controller中添加ExceptionHandler
     * @param request
     * @param response
     * @param ex
     * @return
     */
    @ExceptionHandler(value = Exception.class )
    @ResponseBody //响应的是json数据
    String resolveException(HttpServletRequest request, HttpServletResponse response, Exception ex  ){

        System.out.println(ex.getMessage());
        return "{status:'unup',msg:'出错了'}";
    }


}
